package com.xzz.finger;

/**
 * @author: hhz
 * @create: 2022-02-16 13:36
 * 剑指 Offer 11. 旋转数组的最小数字
 **/
public class MinArray {
    public static void main(String[] args) {
        System.out.println(minArray(new int[]{3,3,3,3,3,3}));
        System.out.println(minArray(new int[]{3,4,5,1,2}));
        System.out.println(minArray(new int[]{1,3,5}));
        System.out.println(minArray(new int[]{2,2,2,0,1}));
    }
    public static int minArray(int[] numbers) {
       int left = 0;
       int right = numbers.length-1;
       while (left<right){
           int mid = left+(right-left)/2;
           if(numbers[mid]>numbers[right]){
               left= mid+1;
           }else if(numbers[mid]<numbers[right]){
               right = mid;
           }else {
               right--;
           }
       }
       return numbers[left];
    }
    public static int minArray2(int[] numbers) {
        int temp = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            if(numbers[i]<temp){
                return numbers[i];
            }
            temp = numbers[i];
        }
        return numbers[0];
    }
}
